<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');



class Em extends CI_Controller {



	     public function __construct()

       {

            parent::__construct();

		$this->load->helper("html");

		$this->load->helper("url");

		$this->load->helper('form');

		$this->load->helper('date');

		$this->load->model("em_model");

		//$this->load->model("guest_comment_model");

		//$this->load->model("news_events_model");

		//$this->load->model("roomcottages_model");

		$this->load->helper(array('form', 'url'));

		$this->load->database();

		

	}

	

	//START ------------------em---------------------

	function index()

	{

		$data['title']="Administrator Page";

		$data["list_ems"] = $this->em_model->get_all_em();	

		$this->load->view('em_list_view',$data);

	}
function SearchCompany()
	{
		$data["list_ems"]=$this->em_model->getemSearchByfull_name($_POST['search']);
		$this->load->view('em_list_view',$data);
	}



	function view_em()

	{
 	    $code = $this->uri->segment(3);
 		$data["info"] = $this->em_model->getem_info($code);	
 		$this->load->view('em_vw_view',$data);}

	

	function add_em()

	{

		//$data["driver_em_data"] = $this->em_model->add_view_driver_em();

		$this->load->view('em_add_view');

	}

	function p_add_em()

	{

		

		$this->load->database();			



		$em_n_name =$_POST['txtem_n_name'];

		$f_name =$_POST['txtf_name'];

		$l_name =$_POST['txtl_name'];

		$address =$_POST['txtaddress'];

		$city =$_POST['txtcity'];			

		$state =$_POST['state'];

		$zipcode =$_POST['txtzipcode'];
		
		$date_of_birth =$_POST['date_of_birth'];

		$cell_phone_num =$_POST['txtcell_phone_num'];

		$alt_phone_num =$_POST['txtalt_phone_num'];			

		$email_add =$_POST['txtemail_add'];

		$em_comment_box =$_POST['txtem_comment_box'];

		//		$contract_amt =$_POST['txtcontract_amt'];

										 

		$_sql="insert into em_profile(profile_type,em_n_name,f_name,l_name,address,city,state,zipcode,date_of_birth,cell_phone_num,alt_phone_num,email_add,em_comment_box)";

		$_sql.="values('em','$em_n_name','$f_name','$l_name','$address','$city','$state','$zipcode','$date_of_birth','$cell_phone_num','$alt_phone_num','$email_add','$em_comment_box')";

		$query = $this->db->query($_sql); 

	/*	$em_id=$this->db->insert_id();

	 

		$_sql="insert into em_contract(em_id,contract_amount)";

		$_sql.="values($em_id,$contract_amt)";

		$query = $this->db->query($_sql); */

			

		$data["list_ems"] = $this->em_model->get_all_em();	

		$this->load->view('em_list_view',$data);

							

	}



	function edit_em()

	{

 	    $code = $this->uri->segment(3);

		$data["info"] = $this->em_model->getem_info($code);	

		$this->load->view('em_edit_view',$data);

	}

	

	function p_edit_em()

	{

		$this->load->database();

	    $employee_code= $_POST['hid_profileid'];

		$em_n_name =$_POST['txtem_n_name'];

		$f_name =$_POST['txtf_name'];

		$l_name =$_POST['txtl_name'];

		$address =$_POST['txtaddress'];

		$city =$_POST['txtcity'];			

		$state =$_POST['state'];

		$zipcode =$_POST['txtzipcode'];
		$date_of_birth =$_POST['date_of_birth'];


		$cell_phone_num =$_POST['txtcell_phone_num'];

		$alt_phone_num =$_POST['txtalt_phone_num'];			

		$email_add =$_POST['txtemail_add'];

		$em_comment_box =$_POST['txtem_comment_box'];

			$query = $this->db->query("UPDATE em_profile SET 

														  	em_n_name='$em_n_name',

														  	f_name='$f_name',

														  	l_name='$l_name',

														  	address ='$address',

															city ='$city',			

															state ='$state',

															zipcode ='$zipcode',
															
															date_of_birth ='$date_of_birth',

														  	cell_phone_num='$cell_phone_num',

														  	alt_phone_num='$alt_phone_num',

														  	email_add='$email_add',

															em_comment_box='$em_comment_box' where employee_code=$employee_code");

														  

		$data["list_ems"] = $this->em_model->get_all_em();	

		$this->load->view('em_list_view',$data);		

	}

	

	

	function delete_em()

	{

		$this->load->database();		

		$code = $this->uri->segment(3);

		$query = $this->db->query("delete from em_profile where employee_code='$code'");

		

		$data["list_ems"] = $this->em_model->get_all_em();	

		$this->load->view('em_list_view',$data);

	}

	//END ------------------em---------------------

	

	

	function logout()

	{

		

		//$this->load->library('session');

		//$this->session->sess_destroy();

		session_start();

		session_destroy();

		//echo $_SESSION['Administrator_log'];

		//unset($_SESSION['Administrator_log']);

		

			//$data["newsresult"] = $this->em_model->em_all_driver_em();

			$this->load->view('admin_view');

	 

	}

 

}

?>